package thired.class03_structure;

public class Class02_ArrayaToStack {
        public static class MyQueue{
            private int[] nums;
            private int pushi;
            private int polli;
            private int size;
            private int limit;
            public  MyQueue(int limit){
                nums = new int[limit];
                pushi = 0;
                polli = 0;
                size = 0;
                this.limit = limit;
            }
            private int nextIndex(int i) {
                return i < limit - 1 ? i + 1 : 0;
            }

            private void push(int val){
                if (size == limit) {
                    throw new RuntimeException("栈满了，不能再加了");
                }
                 nums[pushi] = val;
                 size++;
                 pushi = nextIndex(polli);
            }

            private int pop(){
                if(size <= 0){
                    throw new RuntimeException("栈空了，无元素");
                }
                int res = nums[polli];
                polli = nextIndex(polli);
                size--;
                return res;
            }

            private boolean isEmpty(){
                return size == 0 ;
            }
        }

}
